﻿#建议保存编码为：bom头 + utf8

param
(
	[ValidateNotNullOrEmpty()]
	[Alias("choice")][array]$选项 = @('选择1，立即开始学习powershell','选择2，立即删库跑路','选择3，powershell脚本之巅出品','选择4，群号=183173532')
)


#导入模块，加载dll
if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
	Add-Type -Path "${PSScriptRoot}/Terminal.Gui.ps51.dll" -ErrorAction Stop
}
else
{
	Add-Type -Path "${PSScriptRoot}/Terminal.Gui.dll" -ErrorAction Stop
}

#region code

#endregion code

#region tui
[Terminal.Gui.Application]::Init()
$Window = [Terminal.Gui.Window]::new()
$Window.Title = "PowerShell 多选 tui图形界面例子。按 Ctrl + Q 退出"
$Window.Width = [Terminal.Gui.Dim]::Percent(40)
$Window.Height = [Terminal.Gui.Dim]::Percent(40)
$Window.x = [Terminal.Gui.Pos]::Center()
$Window.y = [Terminal.Gui.Pos]::Center()

$Checkbox0 = [Terminal.Gui.Checkbox]::new()
$Checkbox0.Checked = $true
$Checkbox0.text = $选项[0]
$Window.Add($Checkbox0)

$Checkbox1 = [Terminal.Gui.Checkbox]::new()
$Checkbox1.Checked = $true
$Checkbox1.text = $选项[1]
$Checkbox1.y = [Terminal.Gui.Pos]::Bottom($Checkbox0)
$Window.Add($Checkbox1)

$Checkbox2 = [Terminal.Gui.Checkbox]::new()
$Checkbox2.Checked = $false
$Checkbox2.text = $选项[2]
$Checkbox2.y = [Terminal.Gui.Pos]::Bottom($Checkbox1)
$Window.Add($Checkbox2)

$Checkbox3 = [Terminal.Gui.Checkbox]::new()
$Checkbox3.Checked = $true
$Checkbox3.text = $选项[3]
$Checkbox3.y = [Terminal.Gui.Pos]::Bottom($Checkbox2)
$Window.Add($Checkbox3)

$确定按钮 = [Terminal.Gui.Button]::new()
$确定按钮.y = [Terminal.Gui.Pos]::Bottom($Checkbox3) + 1
$确定按钮.Text = '$true,$false -> $Global: 多 选'
$确定按钮.add_Clicked( {
		$Global:多选 = @($Checkbox0.Checked,$Checkbox1.Checked,$Checkbox2.Checked,$Checkbox3.Checked)
		[Terminal.Gui.Application]::Shutdown()
	})
$Window.Add($确定按钮)
#-------------------------------------------

#endregion tui
[Terminal.Gui.Application]::Top.Add($Window)
[void][Terminal.Gui.Application]::Run()
[void][Terminal.Gui.Application]::Shutdown()
